package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.DateTimeHelper;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * 日期时间
 */
@Data
public class LatexDateTime implements Serializable {
    private int year = 0;

    private int month = 0;

    private int day = 0;

    private int hour = 0;

    private int minute = 0;

    private int second = 0;

    private String dateTimePattern = "yyyy-MM-dd HH:mm:ss";

    private LocalDateTime dateTime = null;

    public String getLatex() {
        return dateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
    }

    public LatexDateTime(int year, int month, int day, int hour, int minute, int second) {
        this.dateTime = DateTimeHelper.dateTimeOf(year, month, day, hour, minute, second);
        if (Objects.nonNull(this.dateTime)) {
            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
        }
    }

    public LatexDateTime(String content) {
        var dateTime = DateTimeHelper.parseDateTime(content);
        if (Objects.nonNull(dateTime)) {
            this.year = dateTime.getYear();
            this.month = dateTime.getMonthValue();
            this.day = dateTime.getDayOfMonth();
            this.hour = dateTime.getHour();
            this.minute = dateTime.getMinute();
            this.second = dateTime.getSecond();
            this.dateTime = dateTime;
        }
    }

    public LatexDateTime(int year, int month, int day, int hour, int minute) {
        this(year, month, day, hour, minute, 0);
    }
}
